import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "首页", icon: "dashboard", breadcrumb: false },
      },
    ],
  },

  {
    path: "/user",
    component: Layout,
    // redirect: "/user/table",
    name: "User",
    meta: { title: "用户管理", icon: "el-icon-user" },
    children: [
      {
        path: "list",
        name: "users",
        component: () => import("@/views/user/index"),
        meta: { title: "用户列表" },
      },
      {
        path: "tree",
        name: "Tree",
        component: () => import("@/views/user_block/index"),
        meta: { title: "封禁用户列表" },
      },
    ],
  },

  {
    path: "/sensitive",
    component: Layout,
    name: "Sensitive",
    meta: { title: "敏感词管理", icon: "el-icon-s-check" },
    children: [
      {
        path: "list",
        name: "sensitiveList",
        component: () => import("@/views/sensitive/index"),
        meta: { title: "敏感词列表" },
      },
      {
        path: "shot",
        name: "sensitive_shot",
        component: () => import("@/views/sensitive_shot/index"),
        meta: { title: "敏感词命中" },
      },
    ],
  },

  {
    path: "/group",
    component: Layout,
    name: "Group",
    meta: { title: "群组管理", icon: "el-icon-orange" },
    children: [
      {
        path: "list",
        name: "group",
        component: () => import("@/views/group/index"),
        meta: { title: "群组列表" },
      },
    ],
  },

  {
    path: "/message",
    component: Layout,
    name: "Message",
    meta: { title: "消息管理", icon: "el-icon-message" },
    children: [
      {
        path: "list",
        name: "message",
        component: () => import("@/views/message/index"),
        meta: { title: "消息列表" },
      },
      {
        path: "user",
        name: "message_user",
        component: () => import("@/views/message_user/index.vue"),
        meta: { title: "用户消息" },
      },
      {
        path: "broadcast",
        name: "broadcast",
        component: () => import("@/views/message_broadcast/index"),
        meta: { title: "广播消息" },
      },
      {
        path: "group",
        name: "message_group",
        component: () => import("@/views/message_group/index"),
        meta: { title: "群发消息" },
      },
    ],
  },

  // {
  //   path: "/robot",
  //   component: Layout,
  //   name: "Robot",
  //   meta: { title: "机器人管理", icon: "el-icon-set-up" },
  //   children: [
  //     {
  //       path: "index",
  //       name: "robot",
  //       component: () => import("@/views/robot/index"),
  //       meta: { title: "机器人列表" },
  //     },
  //   ],
  // },

  // {
  //   path: "/channel",
  //   component: Layout,
  //   name: "Channel",
  //   meta: { title: "频道管理", icon: "el-icon-bangzhu" },
  //   children: [
  //     {
  //       path: "index",
  //       name: "channel",
  //       component: () => import("@/views/channel/index"),
  //       meta: { title: "频道列表" },
  //     },
  //   ],
  // },

  {
    path: "/config",
    component: Layout,
    meta: { title: "设置", icon: "el-icon-setting" },
    children: [
      {
        path: "passwd",
        name: "passwd",
        component: () => import("@/views/config/passwd"),
        meta: { title: "更新密码" },
      },
      {
        path: "avatar",
        name: "avatar",
        component: () => import("@/views/config/avatar"),
        meta: { title: "更新头像" },
      },
      {
        path: "mobile",
        name: "mobile",
        component: () => import("@/views/config/mobile"),
        meta: { title: "更新手机号" },
      },
      {
        path: "max_count",
        name: "max_count",
        component: () => import("@/views/config/max_count"),
        meta: { title: " 群最大人数" },
      },
    ],
  },

  // {
  //   path: "/example",
  //   component: Layout,
  //   redirect: "/example/table",
  //   name: "Example",
  //   meta: { title: "Example", icon: "el-icon-s-help" },
  //   children: [
  //     {
  //       path: "table",
  //       name: "Table",
  //       component: () => import("@/views/table/index"),
  //       meta: { title: "Table", icon: "table" },
  //     },
  //     {
  //       path: "tree",
  //       name: "Tree",
  //       component: () => import("@/views/tree/index"),
  //       meta: { title: "Tree", icon: "tree" },
  //     },
  //   ],
  // },

  // {
  //   path: "/form",
  //   component: Layout,
  //   children: [
  //     {
  //       path: "index",
  //       name: "Form",
  //       component: () => import("@/views/form/index"),
  //       meta: { title: "Form", icon: "form" },
  //     },
  //   ],
  // },

  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true },
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support\
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
